﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using MyMat;
namespace UnitTestMatrix
{
    [TestClass]
    public class TestMymatrix
    {
        [TestMethod]
        public void matrix_Echelon()
        {
            MyMatrix m=new MyMatrix();
            m.Date = new MyVector[3] { new MyVector() { Date = new double[3] { 2, 2.5, 3 } },
                                       new MyVector(){Date=new double[3] { 4, 5, 7.3 }}, 
                                       new MyVector(){Date=new double[3] { 14, 9, 6 }} };
            m.Change_Echelon();
            Assert.AreEqual(m.Date[0].Date[0],2);
            Assert.IsTrue((m.Date[0].Date[1] >= (2.5 - float.Epsilon)) &&
                            (m.Date[0].Date[1] <= (2.5 + float.Epsilon)));
            Assert.AreEqual(m.Date[0].Date[2], 3);
            Assert.AreEqual(m.Date[1].Date[0],0);
            Assert.IsTrue((m.Date[1].Date[1] >= -8.5 - double.Epsilon) && 
                           (m.Date[1].Date[1] <=-8.5+ double.Epsilon));
            Assert.AreEqual(m.Date[2].Date[0], 0);

            Assert.IsTrue((m.Date[2].Date[1] >= - double.Epsilon) && 
                            (m.Date[2].Date[1] <= double.Epsilon));
            Assert.IsTrue((m.Date[2].Date[2] >= 1.3-(1e-10)) &&
                            (m.Date[2].Date[2] <= 1.3 + float.Epsilon));
            
        
        }
        [TestMethod]
        public void matrix_Simple()
        {
            
            MyMatrix m = new MyMatrix();
            m.Date = new MyVector[3] { new MyVector() { Date = new double[4] { 2, 2.5, 3,1 } },
                                       new MyVector(){Date=new double[4] { 4, 5, 7.3 ,1}}, 
                                       new MyVector(){Date=new double[4] { 14, 9, 6 ,1}} };
            m.Change_Simple();
            Assert.AreEqual(m.Date[0].Date[0], 1);
            Assert.IsTrue(m.Date[0].Date[1]==0);
            Assert.AreEqual(m.Date[0].Date[2], 0);
            Assert.AreEqual(m.Date[0].Date[2], 0);
            Assert.IsTrue(m.Date[0].Date[3] >= -409 / 442d - 1E-10 && 
                             m.Date[0].Date[3] <= -409 / 442d + 1E-10);

            Assert.IsTrue(m.Date[1].Date[3] >= 228d /13.0/8.5 - 1E-10 &&
                            m.Date[1].Date[3] <= 228d / 13.0/8.5 + 1E-10);
            Assert.AreEqual(m.Date[1].Date[0], 0);
            Assert.IsTrue((m.Date[1].Date[1] >= 1 - double.Epsilon) &&
                           (m.Date[1].Date[1] <= 1 + double.Epsilon));
            Assert.AreEqual(m.Date[2].Date[0], 0);

            Assert.IsTrue(m.Date[2].Date[1]==0);
            Assert.IsTrue(m.Date[2].Date[2]==1);
            Assert.IsTrue(m.Date[2].Date[3] <= -1 / 1.3 + 1E-10&&m.Date[2].Date[3] >= -1 / 1.3 - 1E-10);

            
        }
        [TestMethod]
        public void matrix_Simple2()
        {
            MyMatrix m = new MyMatrix();
            m.Date = new MyVector[3] { new MyVector() { Date = new double[4] { 0,0,1,0 } },
                                       new MyVector(){Date=new double[4] { 1.2,1.2,1,0}}, 
                                       new MyVector(){Date=new double[4] { 1.2,1.2,1,1.2}} };
            m.Change_Simple();
            Assert.IsTrue(m.Date[0].Date[0] == 1);
            Assert.IsTrue(m.Date[0].Date[1] == 1);
            Assert.AreEqual(m.Date[0].Date[2], 0);
            Assert.IsTrue(m.Date[0].Date[3] ==0);

            Assert.IsTrue(m.Date[1].Date[3] ==0);
            Assert.AreEqual(m.Date[1].Date[0], 0);
            Assert.IsTrue((m.Date[1].Date[2] ==1));
            Assert.IsTrue((m.Date[1].Date[1] == 0));

            Assert.AreEqual(m.Date[2].Date[0], 0);

            Assert.IsTrue(m.Date[2].Date[1] == 0);
            Assert.IsTrue(m.Date[2].Date[2] == 0);
            Assert.IsTrue(m.Date[2].Date[3] ==1);


        }
        [TestMethod]
        public void matrix_Echelon_DeterminantValue()
        {
            MyMatrix m = new MyMatrix();
            m.Date = new MyVector[3] { new MyVector() { Date = new double[3] { 2, 2.5, 3 } },
                                       new MyVector(){Date=new double[3] { 4, 5, 7.3 }}, 
                                       new MyVector(){Date=new double[3] { 14, 9, 6 }} };
            m.Change_Echelon();
            double? value = m.getDeterminantValue();
            Assert.IsTrue(value.HasValue);
            Assert.IsTrue((value >= (-22.1 - 1e-10)) && (value <= -22.1 + 1e-10));
            
        }
    }
}
